package com.onpositive.wiki3.db.catmodel.matches;

import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.catmodel.ICategoryMatcher;
import com.onpositive.wiki3.db.impl.CountingVocabalary;

public final class LargePeriodMatcher implements ICategoryMatcher {
	private final CountingVocabalary vm;
	String[] words = new String[] { "st_millennium", "st_millennium_bc",
			"th_century" };

	public LargePeriodMatcher(CountingVocabalary vm) {
		this.vm = vm;
	}

	@Override
	public int accept(Category st) {
		String title=st.toString();
		for (String s : words) {
			if (title.endsWith(s)) {

				String pref = title.substring(0, title.length() - s.length());
				String toParse = pref;
				try {
					int lastIndexOf = pref.lastIndexOf('_');
					if (lastIndexOf != -1) {
						toParse = pref.substring(lastIndexOf + 1);
						pref = pref.substring(0, lastIndexOf);
					}
					Integer.parseInt(toParse);
					if (pref.endsWith("_established_in_the")) {
						return -1;
					}
					if (pref.endsWith("_completed_in_the")) {
						return -1;
					}
					if (pref.endsWith("_set_in_the")) {
						return -1;
					}
					if (pref.endsWith("_disestablished_in_the")) {
						return -1;
					}
					if (pref.endsWith("_demolished_in_the")) {
						return -1;
					}
					if (pref.endsWith("described_in_the")) {
						return -1;
					}
					if (pref.endsWith("cricket_in_the")) {
						return -1;
					}
					if (pref.endsWith("_novels_of_the")) {
						return -1;
					}
					if (pref.endsWith("_built_in_the")) {
						return -1;
					}
					// _novels_of_the
					if (toParse != pref) {
						// System.out.println(pref);
						vm.add(pref);
					}

				} catch (Exception e) {
					System.out.println(pref);
					// TODO: handle exception
				}

			}
		}
		return -1;
	}
}